// JavaScript Document
var checkDate = function(id,gap)//id of input, break character
{
	var date = new Date;
	var thisYear = date.getFullYear(); 
	var inputContent;
	var isNumber = false;
	document.getElementById(id).onkeyup = function()
	{
		inputContent = this.value;
		var lKeyCode = (navigator.appname=="Netscape")?event.which:window.event.keyCode; //event.keyCode
		if(lKeyCode != 8)
		{
			if(this.value.length == 4) 
			{
				for(i=0;i<5;i++)
				{
					if( isNaN(this.value.substr(0,i)) )
					{
						isNumber = false;
					}
					else{
						isNumber = true;
					}
				}
				if(isNumber)
				{
					if(thisYear - this.value > 120)
					{
						alert("您都超过120岁啦？这不大可能");
						this.value = "";
						document.getElementById(id).focus();
					}
					else if(thisYear - this.value < 18)
					{
						alert("您还未满18岁，不可以参加活动");
						this.value = "";
						document.getElementById(id).focus();
					}
					else{
						this.value = inputContent + gap;
					}
				}
				else
				{
					alert("请全部输入数字");
					this.value = "";
					document.getElementById(id).focus();
				}
			}
			if(this.value.length == 7) 
			{
				for(i=0;i<3;i++)
				{
					if( isNaN(this.value.substr(5,i)) )
					{
						isNumber = false;
					}
					else{
						isNumber = true;
					}
				}
				if(isNumber)
				{
					if(this.value.substr(5,1) == 0)
					{
						if(this.value.substr(6,1) == 0)
						{
							alert("没有0月，请正确输入");
							this.value = inputContent.substr(0,5);
						}
						else
						{
							this.value = inputContent + gap;
						}
					}
					else if(this.value.substr(5,1) == 1 )
					{
						if(this.value.substr(6,1) > 2)
						{
							alert("月份不会超过12，请正确输入");
							this.value = inputContent.substr(0,5);
						}
						else
						{
							this.value = inputContent + gap;
						}
					}
					else
					{
						alert("月份不会超过12，请正确输入");
						this.value = inputContent.substr(0,5);
					}
				}
				else
				{
					alert("请全部输入数字");
					this.value = inputContent.substr(0,5);
					document.getElementById(id).focus();
				}
			}
			if(this.value.length == 10) 
			{
				for(i=0;i<3;i++)
				{
					if( isNaN(this.value.substr(8,i)) )
					{
						isNumber = false;
					}
					else{
						isNumber = true;
					}
				}
				if(isNumber)
				{
					if(this.value.substr(8,1) == 0)
					{
						if(this.value.substr(9,1) == 0)
						{
							alert("日子必须大于0，请正确输入");
							this.value = inputContent.substr(0,8);
						}
					}
					else if(this.value.substr(8,1) == 3)
					{
						if(this.value.substr(5,1) == 0 && this.value.substr(6,1) == 2)
						{
							alert("2月份不会超过29天，请正确输入");
							this.value = inputContent.substr(0,8);
						}
						if(this.value.substr(9,1) > 1)
						{
							alert("月份不会超过31天，请正确输入");
							this.value = inputContent.substr(0,8);
						}
					}
					else if(this.value.substr(8,1) > 3)
					{
						alert("01月份不会超过31天，请正确输入");
						this.value = inputContent.substr(0,8);
					}
				}
				else
				{
					alert("请全部输入数字");
					this.value = inputContent.substr(0,8);
					document.getElementById(id).focus();
				}
			}
		}
	}
}